// ==============================================================================================
// RibbonTreeNode.cs
//
// Created by: NI, 2007.03.27
// Revised by: NI, 2007.11.23
// ==============================================================================================
using System.Windows.Forms;
using RibbonExplorer.Entities;
using RibbonExplorer.InfoPanel;

namespace RibbonExplorer.Tree
{
  // ==============================================================================================
  /// <summary>
  /// This tree node represents a ribbon in the tree.
  /// </summary>
  // ==============================================================================================
  public class RibbonTreeNode : OnDemandTreeNode, IInfoPanelSupport
  {
    #region Private fields

    private Ribbon _Ribbon;

    #endregion

    #region Lifecycle methods

    // --------------------------------------------------------------------------------------------
    /// <summary>
    /// Creates the tree node instance.
    /// </summary>
    /// <param name="ribbon">Ribbon instance for this tree node.</param>
    // --------------------------------------------------------------------------------------------
    public RibbonTreeNode(Ribbon ribbon)
      : base(ribbon.Name)
    {
      _Ribbon = ribbon;
      ImageKey = "Ribbon";
      SelectedImageKey = ImageKey;
      Tag = _Ribbon;
    }

    #endregion

    #region Public properties

    // --------------------------------------------------------------------------------------------
    /// <summary>
    /// Gets the ribbon belonging to the tree node.
    /// </summary>
    // --------------------------------------------------------------------------------------------
    public Ribbon Ribbon
    {
      get { return _Ribbon; }
    }

    #endregion

    #region Overridden methods

    // --------------------------------------------------------------------------------------------
    /// <summary>
    /// Handle the event when the tree node is fisrt time expanded.
    /// </summary>
    // --------------------------------------------------------------------------------------------
    protected override void OnExpandFirstTime()
    {
      base.OnExpandFirstTime();
      _Ribbon.LoadChildren();

      // --- Init Office menu
      Nodes.Add(new OfficeMenuTreeNode(_Ribbon.OfficeMenu));

      // --- Init Quick Access Toolbar
      Nodes.Add(new QatTreeNode(_Ribbon.Qat));

      // --- Init standard tabs belonging to the ribbon
      foreach (RibbonTab tab in _Ribbon.Tabs)
      {
        Nodes.Add(new RibbonTabTreeNode(tab));
      }

      // --- Init tab sets belonging to the ribbon
      foreach (TabSet tabSet in _Ribbon.TabSets)
      {
        Nodes.Add(new TabSetTreeNode(tabSet));
      }

      // --- Init the group of controls not in the ribbon.
      Nodes.Add(new NotInTheRibbonTreeNode(_Ribbon.NotInTheRibbon));
    }

    #endregion

    #region IInfoPanelSupport implementation

    // --------------------------------------------------------------------------------------------
    /// <summary>
    /// Creates an infopanel instance for this tree node type.
    /// </summary>
    /// <param name="node">Tree node instance</param>
    /// <param name="navigationService">Navigation service instance</param>
    /// <returns>
    /// User control instance
    /// </returns>
    // --------------------------------------------------------------------------------------------
    public UserControl GetInfoPanelInstance(TreeNode node, INavigationSupport navigationService)
    {
      GenericInfoPanel control = new GenericInfoPanel(navigationService, node);
      control.HeaderText = "Ribbon: " + node.Text;
      return control;
    }

    #endregion

  }
}
